home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / pascal / tch_tpas.zip / TL15.TXT < prev    next >
Text File  |  1986-04-05  |  6KB  |  212 lines

  1. TURBO-LESSONS - A Pascal Tutorial        Version 1.01    Page 70
  2.  
  3.  
  4. TURBO-LESSON 15:  INTERACTIVE SCREEN HANDLING
  5.  
  6. OBJECTIVES - In this lesson, you will learn about:
  7.  
  8. 1.  Setting up a Data Entry Screen
  9. 2.  Being nice to users - ClrScr
  10. 3.  Getting around the screen - GotoXY
  11. 4.  Screen messages and accepting user input
  12.  
  13.  
  14. 1.  Setting up a Data Entry Screen.
  15.  
  16. For most computer processing applications you will need to 
  17. provide for entry of data.  This is one of the points where your 
  18. programs interact with the person using the program.
  19.  
  20. How your programs are viewed by those using them will depend on 
  21. how well you manage the user-computer interaction on the screen.
  22.  
  23. In this lesson you will try some of the basic techniques of 
  24. screen handling for data entry.
  25.  
  26. ##### DO:
  27.  
  28. Run PROG15.
  29.  
  30. Take a look at the program to see how this screen was produced.
  31.  
  32. ##### DO:
  33.  
  34. Experiment with PROG15.
  35.  
  36. Run the program after each of the following:
  37.  
  38. (1)  Add or delete spaces in the WriteLn statements to move the 
  39. various items.
  40.  
  41. (2)  Line the prompts up on the left.  You may want to keep the 
  42. colons in a vertical column after you move the prompts.
  43.  
  44. (3)  In the main program, add two more statements:
  45.        Print_Entry_Screen;
  46.        Print_Entry_Screen;
  47. î
  48. TURBO-LESSONS - A Pascal Tutorial        Version 1.01    Page 71
  49.  
  50.  
  51. 2.  Being nice to users - ClrScr.
  52.  
  53. Pascal provides a predefined procedure to clear the screen.  
  54.  
  55. Screen interaction will go smoother if unnecessary items are 
  56. removed when no longer needed.  
  57.  
  58. ##### DO:
  59.  
  60. (First, remove the 2 extra Print_Entry_Screen statements.  Notice 
  61. that you could just load a new copy of PROG15.)
  62.  
  63. Add the following statement as the first statement in the main 
  64. program:
  65.  
  66. WriteLn('This is something leftover from previous processing');
  67.  
  68. Run the program.
  69.  
  70. How does the data entry screen look now?
  71.  
  72. This problem was not apparent before, because the screen was 
  73. cleared before the program executed.  The message you just added 
  74. makes the situation more realistic - there are often things left 
  75. on the screen that need to be cleared.
  76.  
  77.  
  78.  
  79. The procedure, ClrScr, will clear the screen.
  80.  
  81. Where should you put ClrScr, in the main program, or in the 
  82. procedure?  
  83.  
  84. Right!  In the procedure, because clearing the screen is really 
  85. just a part of printing the entry screen.
  86.  
  87. ##### DO:
  88.  
  89. At the beginning of the Procedure, Print_Entry_Screen, add:
  90.  
  91. ClrScr;
  92.  
  93. Run the program.   Is the "leftover" message gone?
  94.  
  95. NOTE: YOU SHOULD ALWAYS CLEAR THE SCREEN AS NEEDED.  EARLIER 
  96.       VERSIONS OF TURBO CLEARED THE SCREEN AT THE BEGINNING OF 
  97.       THE PROGRAM, BUT THAT IS THE TYPE OF THING YOU SHOULD NOT 
  98.       DEPEND ON.  WHAT IF THE NEXT VERSION CHANGES?  
  99. î
  100. TURBO-LESSONS - A Pascal Tutorial        Version 1.01    Page 72
  101.  
  102.  
  103. 3.  Getting around the screen - GotoXY.
  104.  
  105. Cursor positioning is done with the predefined procedure, GotoXY.
  106.  
  107. To find out how it works, try PROG15A.
  108.  
  109. ##### DO:
  110.  
  111. Examine PROG15A, then run it a few times using the following 
  112. values for X and Y:
  113.                     X   Y
  114.                     1  20
  115.                    40   1
  116.                    70  23
  117.  
  118. Does GotoXY work the way you expected?  
  119.  
  120. If that is the way you expected it to work, no problem.
  121.  
  122. If you, like me, find that X and Y seem to be reversed, you can 
  123. either learn to use GotoXY as is, or write a procedure to make it 
  124. work the way you want it to!  
  125.  
  126. ##### DO:
  127.  
  128. Add the following procedure before the main BEGIN END block:
  129.  
  130. PROCEDURE Locate(X, Y : Integer);
  131.  
  132. BEGIN
  133.   GotoXY(Y, X);  { Note the reversed Y, X here }
  134. END;
  135.  
  136. Also change the GotoXY(X, Y) statement in the main program to:
  137.  
  138. Locate(X, Y);
  139.  
  140. Run the program several times using the values: 
  141.                   X    Y
  142.                   1   50
  143.                  10    1
  144.                  23   70
  145.  
  146. My own choice is to use GotoXY as is, but if you work in both 
  147. Pascal and Basic at the same time, you might want some procedure 
  148. like Locate, to make the cursor positioning work the same in 
  149. both.  
  150. î
  151. TURBO-LESSONS - A Pascal Tutorial        Version 1.01    Page 73
  152.  
  153.  
  154. 4.  Screen messages and accepting user input.
  155.  
  156. ##### DO:
  157.  
  158. Examine PROCEDURE Get_First_Name in PROG15B.
  159.  
  160. Notice the use of GotoXY(13,3) to position the cursor next to the 
  161. first name prompt on the screen.
  162.  
  163. Read(First_Name) is used instead of ReadLn.  Read and ReadLn will 
  164. be contrasted and explored in a later lesson.  For now, just note 
  165. that the procedure works.
  166.  
  167. ##### DO:
  168.  
  169. Run PROG15B.
  170.  
  171. I hope you got the name right.  No second chance here!
  172.  
  173. Unfortunately, mistakes are made in data entry, and you must 
  174. provide a convenient way to correct them.
  175.  
  176. ##### DO:
  177.  
  178. Look at FUNCTION OK in PROG15C.
  179.  
  180. Also notice how PROCEDURE Get_First_Name has been changed to use 
  181. the information provided by FUNCTION OK.
  182.  
  183. The user can now correct typing mistakes before going on.
  184.  
  185. PROGRAMMING NOTE: OBSERVE THAT FUNCTION OK MUST BE DECLARED 
  186.                   BEFORE PROCEDURE GET_FIRST_NAME SINCE THE 
  187.                   PROCEDURE USES THE FUNCTION.  
  188.  
  189. ##### DO:
  190.  
  191. Run the program, entering a few wrong names of different lengths 
  192. before entering the correct name (your name?)
  193.  
  194. Do you detect a problem?  There are screen leftovers again!  
  195.  
  196. There is another procedure, ClrEol, which clears from the cursor 
  197. position to the end of the line.
  198.  
  199. ##### DO:
  200.  
  201. Insert the statement:   ClrEol;
  202.  
  203. after the GotoXY(1,23) statement in FUNCTION OK and after the 
  204. GotoXY(13,3) statement in PROCEDURE Get_First_Name.  
  205.  
  206. Run the program again, testing for leftovers.  Enter several 
  207. names of different lengths again.
  208.  
  209. How's that?    You're on your way toward friendly input screens!
  210. î
  211.  
  212.